<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/own.css" />
		<link rel="stylesheet" href="../css/iconfont.css" />
		<script type="text/javascript" src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
		<script type="text/javascript" src="../js/common.js"></script>
		<script type="text/javascript">
			mui.init();
			
			var self=null;
			
			var btnArray = null;
			
			var subpages = ['../view/index.html', 'main_scene.html','main_wamange.html']; 
				
			var subpageStyle = { 
				top: '0px', 
				bottom: '2.2rem',
				height: '92%'
			};
			
			
			mui.plusReady(function() {
				plus.navigator.setStatusBarBackground("#007aff");
				plus.navigator.setFullscreen(false); //取消全屏
				plus.screen.lockOrientation('portrait-primary');
				
   				self = plus.webview.currentWebview();
   				 
				for(var i = 0; i <1; i++) {
					var sub = plus.webview.create(subpages[i], subpages[i], subpageStyle);
					if (i > 0) {  
						sub.hide();  
					    } 
					
					self.append(sub);
				}
				
                var activeTab = subpages[0];
                
				mui(".mui-bar-tab").on("tap", "a", function(e) {
					
					var targetTab = this.getAttribute("href");
					if(targetTab != 'main_scene.html'){
						//获取token
					    var params = {
								'user':localStorage.getItem('useid'),
								'pswd':localStorage.getItem('pswd')
							}
							mpms_ajax(params,'getToken',function(data){
								localStorage.setItem('token',data.token);
					     });
					}
					
					
					if (targetTab == activeTab) {
								return;
							}
					 
					var sub = plus.webview.create(targetTab, targetTab, subpageStyle);  
					
					self.append(sub);  
					
					mui.fire(plus.webview.getWebviewById(targetTab),'newsId',{url:this.title});
					
					plus.webview.close(activeTab);
					
					activeTab = targetTab;
					
				});
				pageajaxdata();
				
			});
			
		function evenPage(str){
			mui.fire(plus.webview.getWebviewById('../view/index.html'),'newsId',{url:str});
		}
		
		function pageajaxdata(){
		 	  mpms_ajax({'node':localStorage.getItem('node')},'getNodeData',function(data){
					if(data.data.menu.length>0){
						//存储node节点数据
					  for (let value of data.data.menu) {
				            if (value.title == '主页') {
				            	$('#zy').show();
				            	 evenPage(value.href);
				            	$('#zy').attr('title',value.href);
				            } else if(value.title == '现场'){
				            	$('#xc').show();
				            	 $('#xc').attr('title',value.href);
				            } else if(value.title == '管理'){
				            	$('#cgl').show();
				            	if(value.list.length>0){
				            	  $('#cgl').attr('title','');	
				            	}
				            }
					   }
					  if(!isNull(data.data.nodelist)){
				       btnArray = [];
					   for (let value of data.data.nodelist) {
          	 			   for(var key in value){
          	 			  	        job = new Object();
									job.id = key;
									job.title = value[key];
									btnArray.push(job);
							}
					   }
				    }
					}
				  });
		 
		}
		function setshow(){
				plus.nativeUI.actionSheet({
				title:"切换节点",
				cancel:"退出",
				buttons:btnArray
			}, function(e){
				var index = e.index;
				if(index == '0'){
					logout();
				}else if(index == '-1'){//取消
            
				}else{
					 localStorage.setItem('node',btnArray[index-1].id);
					 plus.runtime.restart();
					
				}
		});
			
		}
		
		
		</script>
	</head>

	<body>
		<div class="mui-content">
			<footer class="mui-bar mui-bar-footer">
				<nav class="mui-bar mui-bar-tab">
					<a class="mui-tab-item mui-active" title=""  href="../view/index.html"  style="display: none;" id="zy">
						<span class="mui-icon mui-icon-home"></span>
						<span class="mui-tab-label">主页</span>
					</a>
					<a class="mui-tab-item"  href="main_scene.html" title="" style="display: none;" id="xc">
						<span class="mui-icon iconfont icon-xianchang"></span>
						<span class="mui-tab-label">现场</span>
					</a>
					<a class="mui-tab-item"  href="main_admin.html"  title="" style="display: none;" id="cgl">
						<span class="mui-icon iconfont icon-cangku"></span>
						<span class="mui-tab-label">管理</span>
					</a>
				</nav>
			</footer>
		</div>
	</body>

</html>